In computing, a data source name (DSN, sometimes known as a database source name though data sources are not limited to databases) are data structures used to describe a connection to a data source. Most commonly used in reference to ODBC, DSNs may also be defined for JDBC and other data access mechanisms.
DSN attributes may include, but are not limited to:
The system administrator of a client machine creates a separate DSN for each relevant data source.
Standardizing DSNs offers a level of indirection that various applications (for example: Apache/PHP and IIS/ASP) can take advantage of in accessing shared data sources.
Contents |
Two kinds of DSN exist:
These are further broken down into
The term DSN is sometimes mistakenly used in place of connection string. A connection string typically fully describes a data source, while a DSN typically relies on some external system resources and/or configuration files.
Software (e.g., Crystal Reports, Microsoft Excel, PHP, Perl, Python, Ruby) users can submit CRUD (Create, Read, Update, Delete) queries to a data source by establishing a connection to the DSN.
ASP (VBScript) code to open a DSN connection might look like the following:
Dim DatabaseObject1 Set DatabaseObject1 = Server.CreateObject("ADODB.Connection") DatabaseObject1.Open("DSN=DSNname;")
In PHP using the PEAR::DB package to open a connection without an external DSN (a "DSN-less connection", i.e., using a Connection String), the code might resemble the following:
require_once("DB.php"); //$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>"; $dsn = "mysql://john:pass@localhost:port/my_db"; $db = DB::connect($dsn);
|